<?php
/**
 * Created by PhpStorm.
 * User: 12133
 * Date: 2024/1/17
 * Time: 17:22
 */
namespace app\controller\home;

use app\model\home\Nav;
use app\model\home\Website;
use app\model\home\Content;

class Index extends Base
{
    protected $nav;
    protected $web;
    protected $content;
    public function __construct(){
        parent::__construct();
        $this->nav = Nav::withoutGlobalScope();
        $this->web = Website::withoutGlobalScope();
        $this->content = Content::withoutGlobalScope();
    }

    public function index(){
        return $this->view(
            '/home/index'
        );
    }

    public function web($id = 0){
        if (empty($id))
            return $this->msg(['websitr' => $this->website]);
        cache('wid',$id);
        return $this->success('选择成功','/home/list/web');
    }

    public function html($id){
        $web = $this->web
            ->where('id',$id)
            ->find();
        $nav = $this->nav
            ->where('pid',0)
            ->where('website_id',$id)
            ->with(['son'])
            ->order('sort ASC')
            ->select();
        $content = $this->content
            ->where('website_id',$id)
            ->where('status',1)
            ->order('create_time DESC')
            ->limit(20)
            ->select();
        return $this->msg([
            'nav' => $nav,
            'web' => $web,
            'content' => $content
        ]);
    }

    public function info($id,$type = 'nav'){
        if ($type == 'nav'){
            $info = $this->nav->where('id',$id)->find();
            return $this->msg(['content' => $info->content]);
        }
        return $this->msg();
    }
}